# coding: utf-8
from sqlalchemy import BigInteger, Column, DateTime, ForeignKey, Integer, String
from sqlalchemy.schema import FetchedValue
from sqlalchemy.orm import relationship
from flask_sqlalchemy import SQLAlchemy
from common.models.User import User
from common.models.Storage import Storage
from  application import  db

class Food(db.Model):
    __tablename__ = 'food'

    fid = db.Column(db.BigInteger, primary_key=True, nullable=False, info='????')
    foodpos = db.Column(db.ForeignKey('storage.sid', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True, nullable=False, index=True, server_default=db.FetchedValue(), info='??????')
    mobile = db.Column(db.String(20), nullable=False, server_default=db.FetchedValue(), info='??????')
    opsid = db.Column(db.ForeignKey('user.uid'), nullable=False, index=True, info='?????')
    created_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue(), info='????')

    storage = db.relationship('Storage', primaryjoin='Food.foodpos == Storage.sid', backref='foods')
    user = db.relationship('User', primaryjoin='Food.opsid == User.uid', backref='foods')